#!/usr/bin/perl

print "Gb tool analyser. \n";

open INPUT, "<", "log.txt" or die $!;
#open $fin, "<", "log.txt" or die $!;
open $fout, ">", "output.txt";

$line_number = 0;
$line = 1;
@array;

@array = <INPUT>;

close ($fin);

print "Enter the NSEI: ", "\n";
$NSEI = <>;
chomp ($NSEI);
print $NSEI;
for ($i = 0; $i < scalar(@array); $i++)	
{
	chomp (@array[$i]);
	if (@array[$i] =~ /$NSEI/i and (@array[$i-2] =~ /ALARM/ or @array[$i-2] =~ /CANCEL/) )
	{
#		$j = $i-3;
#		print @array[$j], "\n";
#		print @array[$j+1], "\n";
#		print @array[$j+2], "\n";
			
#		print @array[$i-3], "\n";
#		print $fout @array[$i-3],"\n";
##		@string1 = split /\s+/,@array[$i-3];
#		print @string1[0], "\n";
#		print @string1[1], "\n";
#		print @string1[2], "\n";
#		print @string1[3], "\n";
#		print @string1[4], "\n";
#		print @string1[5], "\n";
#		print @string1[6], "\n";
#		print "\n";
#		print @array[$i-2], "\n";
#		print $fout @array[$i-2],"\n";
##		@string2 = split /\s+/,@array[$i-2];
#		print @string2[0], "\n";
#		print @string2[1], "\n";
#		print @string2[2], "\n";
#		print @string2[3], "\n";
#		print @string2[4], "\n";
#		print "\n";

#		print @array[$i-1], "\n";
#		print $fout @array[$i-1], "\n";
##		@string3 = split /\s+/,@array[$i-1];
#		print @string3[0], "\n";
#		print @string3[1], "\n";
#		print @string3[2], "\n";
#		print @string3[3], "\n";
#		print @string3[4], "\n";
#		print @string3[5], "\n";
#		print @string3[6], "\n";
#		print @string3[7], "\n";
#		print @string3[8], "\n";
#		print @string3[9], "\n";
#		print "\n";

		print @array[$i], "\n";
#		print $fout @array[$i], "\n";
		@string4 = split /\s+/,@array[$i];
		print @string4[0], "\n";
		print @string4[1], "\n";
		print @string4[2], "\n";
		print @string4[3], "\n";
		print @string4[4], "\n";
		print @string4[5], "\n";
		print @string4[6], "\n";
		print @string4[7], "\n";
		print @string4[8], "\n";
		print @string4[9], "\n";
		print @string4[22], "\n";
		print "\n";
	}
}





close ($fout);

